package com.songyang.blog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.code.kaptcha.Producer;
import com.songyang.blog.entity.User;
import com.songyang.blog.service.*;
import com.songyang.blog.util.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {

    @Autowired
    CheckCodeUtil checkCodeUtil;
    @Autowired
    UploadUtil uploadUtil;

    @Autowired
    Producer producer;//谷歌验证码
    @Autowired
    RedisUtil redisUtil;

    @Autowired
    HttpServletRequest request;
    @Autowired
    ShiroUtils shiroUtils;

    @Autowired
    HttpServletResponse response;

    @Autowired
    PostService postService;

    @Autowired
    CommentService commentService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    UserService userService;

    @Autowired
    UserMessageService messageService;

    @Autowired
    UserCollectionService collectionService;

    @Autowired
    CategoryService categoryService;

    @Autowired
    WsService wsService;

    @Autowired
    SearchService searchService;

    @Autowired
    AmqpTemplate amqpTemplate;



//    @Autowired
//    ChatService chatService;

    public Page getPage() {//抽取出来页码
        int pn = ServletRequestUtils.getIntParameter(request, "pn", 1);
        int size = ServletRequestUtils.getIntParameter(request, "size", 10);
        return new Page(pn, size);
    }

    public Page getPage(int pn, int size) {//抽取出来页码
        return new Page(pn, size);
    }

    protected User getProfile() {
        return (User) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getProfileId() {//获得当前 用户的id
        return getProfile().getId();
    }

}
